﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminMaster.Master" AutoEventWireup="true" CodeBehind="Notification.aspx.cs" Inherits="MonitorPlan.Admin.Notification" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Notification Settings</title>
    <script>
        $(document).ready(function () {
            $("a#btnNotification").css("background", "#CCC");
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <%-- sqldatasource to get user name --%>
            <asp:SqlDataSource ID="dsUser" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select * from users where isdeleted=0"></asp:SqlDataSource>

             <%-- sqldatasource to get tools --%>
            <asp:SqlDataSource ID="dsTool" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select * from tool where isdeleted=0"></asp:SqlDataSource>

            <%-- sqldatasource to get house name --%>
            <asp:SqlDataSource ID="dsHouse" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                  SelectCommand="select houseid, housename from house where isdeleted=0"></asp:SqlDataSource>

            <%-- sqldatasource to get notification settings --%>
            <asp:SqlDataSource ID="dsNotification" runat="server" ConnectionString="<%$ ConnectionStrings:conStr %>"
                 SelectCommand="select [notification].notificationid, [notification].toolid, tool.toolname, house.housename, users.username, [notification].whentonotify from [notification] inner join tool on [notification].toolid=tool.toolid inner join house on [notification].houseid=house.houseid inner join users on [notification].userid = users.userid">

            </asp:SqlDataSource>
            <%-- top menu buttons --%>
            <ul class="nav nav-pills action-buttons">
                <li><asp:LinkButton ID="btnView" runat="server" OnClick="btnView_Click">
                    <i class="icon icon-view"></i>&nbsp;View</asp:LinkButton></li>
                 <li>
                     <asp:LinkButton ID="btnAdd" runat="server" OnClick="btnAdd_Click">
                         <i class="icon icon-add"></i>&nbsp;Add New
                     </asp:LinkButton>
                 </li>
            </ul>

              <%-- multiview for insert, view, edit and detail view for notifications --%>
            <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">
                <asp:View ID="vNotification" runat="server">
                    <h5 class="text-info">View Notification Settings</h5>
                     <asp:Repeater ID="rp1" runat="server" DataSourceID="dsNotification">
                        <HeaderTemplate>
                             <table class="table table-condensed table-striped table-hover">
                                <tr>
                                    <th>Not. Id</th>
                                    <th>Tool Id</th>
                                    <th>Tool Name</th>
                                    <th>House Name</th>
                                    <th>User Name</th>
                                    <th>Notify When</th>
                                    <th>Actions</th>
                                </tr>
                        </HeaderTemplate>
                         <ItemTemplate>
                             <tr>
                                 <td><%# Eval("notificationid") %></td>
                                 <td><%# Eval("toolid") %></td>
                                 <td><%# Eval("toolname") %></td>
                                 <td><%# Eval("housename") %></td>
                                 <td><%# Eval("username") %></td>
                                 <td><%# Eval("whentonotify") %></td>
                                  <td>
                                    <%-- the command button to edit, delete and view detail for each notification setting --%>
                                    <asp:LinkButton ID="btnDetail" runat="server"
                                        CommandName="detail" CommandArgument='<%# Eval("notificationid") %>'>
                                        Detail</asp:LinkButton>&nbsp;
                                     <asp:LinkButton ID="btnEdit" runat="server" 
                                        CommandName="edit" CommandArgument='<%# Eval("notificationid") %>'>
                                        Edit</asp:LinkButton>&nbsp;
                                    <asp:LinkButton ID="btnDelete" runat="server"
                                        CommandName="delete" CommandArgument='<%# Eval("notificationid") %>' OnClientClick="return confirm('You want to delete it?');">
                                        Delete
                                    </asp:LinkButton>
                                </td>
                             </tr>
                         </ItemTemplate>
                         <FooterTemplate>
                             </table>
                         </FooterTemplate>
                    </asp:Repeater>
                </asp:View>

                <%-- view to add new notification settings --%>
                <asp:View ID="vAddNotification" runat="server">
                    <h5 class="text-info">Add New Notification Setting</h5>
                    <label for="ddlUser">User Name</label>
                    <asp:DropDownList runat="server" ID="ddlUser" AutoPostBack="true" Width="314" DataSourceID="dsUser"
                         DataTextField="username" DataValueField="userid" OnSelectedIndexChanged="ddlUser_SelectedIndexChanged"></asp:DropDownList>
                    <label for="ddlHouse">House Name</label>
                    <asp:DropDownList ID="ddlHouse" runat="server" AutoPostBack="true" Width="314" DataSourceID="dsHouse"
                         DataTextField="housename" DataValueField="houseid" OnSelectedIndexChanged="ddlHouse_SelectedIndexChanged"></asp:DropDownList>
                    <label for="ddlTool">Tool Name</label>
                    <asp:DropDownList ID="ddlTool" runat="server" AutoPostBack="true" Width="314" DataSourceID="dsTool"
                         DataTextField="toolname" DataValueField="toolid"></asp:DropDownList>
                    <label for="ddlNotify">When To Notify</label>
                    <asp:DropDownList ID="ddlNotify" runat="server" AutoPostBack="false" Width="314">
                        <asp:ListItem Value="on">on</asp:ListItem>
                        <asp:ListItem Value="off">off</asp:ListItem>
                    </asp:DropDownList>
                    <br />
                    <label class=" radio inline">Send SMS to phone?</label>
                    <label class="radio inline">
                        <asp:RadioButton ID="rdSms" runat="server" Checked="true" GroupName="rdg" Text="No" />
                    </label>
                     <label class="radio inline">
                        <asp:RadioButton ID="rdSms1" runat="server" Checked="false"  GroupName="rdg" Text="Yes" />
                    </label>
                    <br />
                    <label class="radio inline">Set alarm sound?</label>
                    <label class="radio inline">
                        <asp:RadioButton ID="rdAlarm" runat="server" Checked="true" GroupName="rda" Text="No" OnCheckedChanged="rdAlarm_CheckedChanged" AutoPostBack="true" />
                    </label>
                    <label class="radio inline">
                        <asp:RadioButton ID="rdAlarm1" runat="server" Checked="false" GroupName="rda" Text="Yes" OnCheckedChanged="rdAlarm1_CheckedChanged" AutoPostBack="true" />
                    </label>
                    <br />
                    <asp:Panel ID="pnAlarm" runat="server" Enabled="false" Height="95px">
                        <b>Start Time:</b> <asp:TextBox ID="txtH" runat="server" Width="60" placeholder="hour"></asp:TextBox>
                        <asp:TextBox ID="txtMinute" runat="server" Width="60" placeholder="minute"></asp:TextBox>
                        <asp:DropDownList ID="ddlAMPM" runat="server" Width="65">
                            <asp:ListItem Value="AM">AM</asp:ListItem>
                            <asp:ListItem Value="PM">PM</asp:ListItem>
                        </asp:DropDownList>
                        <br />
                        <b>End&nbsp; Time: </b><asp:TextBox ID="txtHEnd" runat="server" Width="60" placeholder="hour"></asp:TextBox>
                        <asp:TextBox ID="txtMinuteEnd" runat="server" Width="60" placeholder="minute"></asp:TextBox>
                        <asp:DropDownList ID="ddlAMPMEnd" runat="server" Width="65">
                             <asp:ListItem Value="AM">AM</asp:ListItem>
                            <asp:ListItem Value="PM">PM</asp:ListItem>
                        </asp:DropDownList>
                    </asp:Panel>
                    <%-- The button to save, cancel and go back --%>
                      <asp:LinkButton ID="btnSave" runat="server" CssClass="btn btn-primary btn-small" OnClick="btnSave_Click">
                        <i class="icon-ok-circle icon-white"></i> Save</asp:LinkButton>
                    <asp:LinkButton ID="btnCancel" runat="server" CssClass="btn btn-danger btn-small" OnClick="btnCancel_Click">
                        <i class="icon-remove-sign icon-white"></i> Cancel</asp:LinkButton>
                    <asp:LinkButton ID="btnClose" runat="server" CssClass="btn btn-success btn-small" OnClick="btnClose_Click">
                        <i class="icon-arrow-left icon-white"></i> Back</asp:LinkButton>
                    <br /><br />
                    <div runat="server" id="actionSms"></div>   
                </asp:View>
            </asp:MultiView>
        </ContentTemplate>

    </asp:UpdatePanel>
</asp:Content>
